package com.fy56.platform.fileupload.encoding;

import javax.servlet.*;
import java.io.IOException;

/**
 * 解决项目乱码问题
 *
 * @author frank
 */
public class Encoding implements Filter {
    private String encoding = null;

    public void destroy() {
        this.encoding = null;

    }

    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        if (encoding != null){
            request.setCharacterEncoding(encoding);
        }
        chain.doFilter(request, response);

    }

    public void init(FilterConfig arg0) throws ServletException {
        this.encoding = arg0.getInitParameter("encoding");

    }

}
